<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="./../templates/template.xhtml">
    <ui:define name="titulo">
        Informe de Costos de Inventario
    </ui:define>    
    <ui:define name="content">
        <script type="text/javascript" language="javascript" >
             function openPopupFunction() {
openPopup.jq.click();
}

function doPopup(source,title){
popup=window.open (source, "popup", "height=600, width=900");
popup=document.title = title;
popup.focus();
}            
            
function confirmFunction() {
updateConfim.jq.click();
}
        </script>
        <p:panel header="Informe de Costos">
            <p:growl life="6000" id="msg" globalOnly="true" showDetail="true"/>
            <h:panelGrid id="campos" style="width: 100%">
                <p:fieldset legend="Mes">
                    <h:panelGrid columns="3">
                         <h:outputText value="Año:"/>
                <p:spinner id="txtAnio" binding="#{txtAnio}" onchange="seleccionarMes()" value="#{informeCostosBean.selectedAnio}" size="30" stepFactor="1" min="2011" style="width: 200px"/>
                <p:message for="txtAnio"/>
                        <h:outputText value="Mes:"/>
                        <h:selectOneMenu id="cboMes" onchange="seleccionarMes()" value="#{informeCostosBean.selectedMes}" binding="#{cboMes}" style="width: 200px">
                            <f:selectItem itemLabel="-Seleccione un mes-" itemValue="#{null}"></f:selectItem>
                            <f:selectItems value="#{informeCostosBean.listaMeses}" />
                        </h:selectOneMenu>
                        <p:message for="cboMes"/>           
                    </h:panelGrid>
                </p:fieldset>
                
                
                
            </h:panelGrid>
        </p:panel>
        <f:facet name="footer">
                    <h:panelGrid style="width: 400px; text-align: left;" columns="3">
                        <h:outputText value="Exportar como:" />
                        <h:selectOneMenu style="width: 200px" id="cboTipo" value="#{informeCostosBean.selectedTipo}" >
                            <f:selectItem itemLabel="-Seleccione una opcipón-" itemValue="#{null}"/>
                            <f:selectItem itemLabel="Documento PDF" itemValue="application/pdf"/>
                            <f:selectItem itemLabel="Documento EXCEL" itemValue="application/vnd.ms-excel"/>
                            <f:selectItem itemLabel="Documento HTML" itemValue="text/html"/>
                        </h:selectOneMenu> 
                        <p:commandButton type="push" 
                                         value="Imprimir" 
                                         oncomplete="openPopupFunction()" 
                                         update="openPopup campos" 
                                         action="#{informeCostosBean.imprimir}" 
                                         title="Imprimir" 
                                         image="ui-icon-arrowthickstop-1-s"/> 
                         </h:panelGrid> 
                </f:facet> 

        <p:dataTable id="dtCostos" rows="10" paginator="true" value="#{informeCostosBean.listaCostos}" var="varCostos">
            <f:facet name="header">  
                Informe Costos
            </f:facet> 
            <p:column style="text-align:left">  
                <f:facet name="header">  
                    <h:outputText value="Categoria" />  
                </f:facet>  
                <h:outputText value="#{varCostos[1]}" />  
            </p:column>
            <p:column style="text-align:left">  
                <f:facet name="header">  
                    <h:outputText value="Artículo" />  
                </f:facet>  
                <h:outputText value="#{varCostos[2]}" />  
            </p:column>
            <p:column style="text-align:right">  
                <f:facet name="header">  
                    <h:outputText value="Consumo" />  
                </f:facet>  
                <h:outputText value="#{varCostos[3]}" />  
            </p:column>
            <p:column style="text-align:right">  
                <f:facet name="header">  
                    <h:outputText value="Precio ($USD)" />  
                </f:facet>  
                <h:outputText value="#{varCostos[4]}" />  
            </p:column>
            <p:column style="text-align:right">  
                <f:facet name="header">  
                    <h:outputText value="Total ($USD)" />  
                </f:facet>  
                <h:outputText value="#{varCostos[5]}" />  
            </p:column>
           
           
        </p:dataTable>
        
        <p:remoteCommand name="seleccionarMes" process="@this txtAnio cboMes" action="#{informeCostosBean.populateInformeCostos()}" update="dtCostos">  
                <f:setPropertyActionListener value="#{cboMes.value}" target="#{informeCostosBean.selectedMes}" /> 
            </p:remoteCommand>
        <p:commandButton style="visibility: hidden" 
                         widgetVar="updateConfim" 
                         update="dtSalida msg"/>
        
        <p:commandButton id="openPopup" 
                         style="visibility: hidden" 
                         onclick="doPopup('#{informeCostosBean.url}', 'Informe de Costos')"
                         widgetVar="openPopup"/>
        
    </ui:define>
</ui:composition>

